// 基于 SnowLang Project (https://gitee.com/jcnc-org/snow) 的衍生作品
// 原始版权归属: Copyright © 2025 Ke Xu (Luke)
// 本实现版权归属: Copyright © 2025 Sany
// 遵循 Apache License 2.0 授权
package io

import (
	"gitee.com/xntk2381/cc/vm/utils"
)

/**
 * The FilePathResolver class handles command-line arguments to retrieve a valid file path.
 * This class contains a method that extracts the file path from the command-line arguments.
 * If no file path is provided, an error message will be logged.
 * <p>
 * The main functionality of this class is to obtain the file path from the command-line arguments and provide relevant error logging.
 * </p>
 */
type filePathResolver struct{}

/**
 * Default constructor for creating an instance of FilePathResolver.
 * This constructor is empty as no specific initialization is required.
 */
func NewFilePathResolver() *filePathResolver {
	return &filePathResolver{}
}

var FilePathResolver = NewFilePathResolver()

/**
 * Retrieves the file path.
 * <p>
 * This method calls the method in the FileIOUtils class to obtain the file path from the command-line arguments.
 * If a valid file path is not provided, an error message will be logged.
 * </p>
 *
 * @param args Command-line arguments containing the file path provided by the user
 * @return The file path if a valid path is provided in the command-line arguments; otherwise, returns null.
 */
func (r *filePathResolver) GetFilePath(args []string) string {
	filePath := GetFilePathFromArgs(args)

	if filePath == "" {
		utils.LogError("No valid file path provided.")
	}

	return filePath
}
